package com.suitsoft.ut.service.commons;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;

import com.google.common.collect.Lists;
import com.suitsoft.ut.dao.account.SystemInfoDao;
import com.suitsoft.ut.dao.base.StudentDao;
import com.suitsoft.ut.dao.commons.ExpDao;
import com.suitsoft.ut.dao.thesis.ThesisDao;
import com.suitsoft.ut.entity.base.Student;
import com.suitsoft.ut.entity.commons.Weeklydiary;
import com.suitsoft.ut.entity.system.SystemInfo;
import com.suitsoft.ut.entity.thesis.Thesis;
import com.suitsoft.ut.entity.thesis.ThesisFile;
import com.suitsoft.ut.entity.thesis.ThesisScore;
import com.suitsoft.ut.util.DateUtils;
import com.suitsoft.ut.util.WordUtils;

/**
 * 导出
 *@author Suine
 */
@Service
@Transactional
public class ExpManager {
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private ExpDao dao;
	@Autowired
	private ThesisDao thesisDao;
	@Autowired
	private SystemInfoDao systemDao;
	@Autowired
	private StudentDao studentDao;
	//立题 
	private final String PATH_LITIDOC = "WEB-INF/exp/template/liti.doc";
	private final String PATH_LITICONTENT = "WEB-INF/exp/template/liti-content";
	private final String TEMP_PATH = "WEB-INF/exp/temp/";
	//任务书
	private final String PATH_TASKDOC = "WEB-INF/exp/template/task.doc";
	private final String PATH_TASCKCONTENT = "WEB-INF/exp/template/task-content";
	//情况表
	private final String PATH_QINGKUANG_DOC = "WEB-INF/exp/template/qingkuang.doc";
	private final String PATH_QINGKUANG_CONTENT = "WEB-INF/exp/template/qingkuang-content";
	//开题报告 
	private final String PATH_REPORT_DOC = "WEB-INF/exp/template/open-report.doc";
	private final String PATH_REPORT_CONTENT = "WEB-INF/exp/template/open-report-content";
	
	//周记
	private final String PATH_WEEK = "WEB-INF/exp/template/weeks.doc";
	private final String PATH_WEEK_CONTENT = "WEB-INF/exp/template/weeks-content";
	//总结
	private final String PATH_WEEK_END = "WEB-INF/exp/template/weeks_end.doc";
	private final String PATH_WEEK_END_CONTENT = "WEB-INF/exp/template/weeks_end-content";
	
	//理科答辩 指导教师
	private final String PATH_LI_KE_ZHIDAO = "WEB-INF/exp/template/like_zhidao.doc";
	private final String PATH_LI_KE_ZHIDAO_CONTENT = "WEB-INF/exp/template/like_zhidao-content";
	
	//理科答辩 评阅教师
	private final String PATH_LI_KE_PINGYUE = "WEB-INF/exp/template/pingyue.doc";
	private final String PATH_LI_KE_PINGYUE_CONTENT = "WEB-INF/exp/template/pingyue-content";
	
	//理科答辩 答辩委员会
	private final String PATH_LI_KE_DABIAN = "WEB-INF/exp/template/dabian.doc";
	private final String PATH_LI_KE_DABIAN_CONTENT = "WEB-INF/exp/template/dabian-content";
	
	/** 立题 */
	private final Long LITI = 1L;
	/** 任务书*/
	private final Long TASK = 2L;
	/** 开题情况表 */
	private final Long QINGKUANG = 3L;
	/** 开题报告 */
	private final Long REPORT = 4L;
	/** 周记 */
	private final Long WEEK = 5L;
	/** 第3-4周 */
	private final Long WEEK_3_4 = 6L;
	/** 第5-6 */
	private final Long WEEK_5_6 = 7L;
	/** 第7-8 */
	private final Long WEEK_7_8 = 8L;
	/** 第9-10 */
	private final Long WEEK_9_10 = 9L;
	/** 第11-12 */
	private final Long WEEK_11_12 = 10L;
	/** 第13-14 */
	private final Long WEEK_13_14 = 12L;
	/** 第15-16 */
	private final Long WEEK_15_16 = 13L;
	/** 总结 */
	private final Long WEEK_END = 14L;
	
	
	public void findByPage(Page<Map<String,Object>> page,String colloge,String zhuanye,String studentNo,String studentName,String teacherName,String teacherNos){
		dao.find(page, colloge, zhuanye, studentNo, studentName, teacherName, teacherNos);
	}
	/**
	 * 导出
	 * @param ids
	 * @param flag
	 */
	public String exp(List<Long> ids,List<Long> flag,String webPath){
		
		//把list<Id>整理到map中
		Thesis thesis = null;
		/** key -班级，value - 班级的所有题目 */
		Map<String,List<Thesis>> map = new HashMap<String,List<Thesis>>();
		List<Thesis> list = null;
		Student student = null;
		for(Long id : ids){
			thesis = thesisDao.get(id);
			student = studentDao.findUniqueBy("studentNo", thesis.getStudentNo());
			list = map.get(student.getClasses());
			if(list == null || list.isEmpty()){
				list = new ArrayList<Thesis>();
				list.add(thesis);
				map.put(student.getClasses(), list);
			}else{
				list.add(thesis);
			}
		}
		String desPath = null;
		//每次操作获取的所有文件都放在一个目录下.便与后期压缩
		String nowTime = new Date().getTime() + "";
		
		for(Long f : flag){
			if(LITI.equals(f)){
				desPath = multLiti(map,webPath,nowTime);
			}else if(TASK.equals(f)){
				desPath = multTask(map, webPath, nowTime);
			}else if(QINGKUANG.equals(f)){
				desPath = multQingkuang(map, webPath, nowTime);
			}else if(REPORT.equals(f)){
				desPath = multOpenReport(map, webPath, nowTime);
			}else if(WEEK_3_4.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 3L);
			}else if(WEEK_5_6.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 5L);
			}else if(WEEK_7_8.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 7L);
			}else if(WEEK_9_10.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 9L);
			}else if(WEEK_11_12.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 11L);
			}else if(WEEK_13_14.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 13L);
			}else if(WEEK_15_16.equals(f)){
				desPath = multWEEK(map, webPath, nowTime, 15L);
			}else if(WEEK_END.equals(f)){
				desPath = multWEEKEnd(map, webPath, nowTime);
			}
			
		}
		return desPath;
		
	}
	
	public String multLiti(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String litidoc = webPath + PATH_LITIDOC;
		String litiContent = webPath + PATH_LITICONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/立题论证书/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(litidoc,litiContent);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(liti(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	/**
	 * 单个
	 * @param id
	 * @param webPath
	 * @return
	 */
	private Map<String,String> liti(Thesis thesis){
		
		Map<String,String> m = new HashMap<String,String>();
		m.put("#{yuanxi}", thesis.getCollege().getCollegeName() == null ? "" : thesis.getCollege().getCollegeName());
		m.put("#{zhuanye}", thesis.getDiscipline().getDisciplineName() == null ? "" : thesis.getDiscipline().getDisciplineName());
		m.put("#{teacher_Name}", thesis.getTeacherName() == null ? "" : thesis.getTeacherName());
		m.put("#{teacher_post}", thesis.getTeacherPost() == null ? "" : thesis.getTeacherPost());
		
		String date = thesis.getSetTheTime() == null ? "" : DateUtils.toString(thesis.getSetTheTime());
		
		m.put("#{date}", date);
		m.put("#{titile}", thesis.getTitile());
		
		/** 科题来源 */
		SystemInfo systemInfo = systemDao.get(Long.valueOf(thesis.getKetiSource()));
		m.put("#{timu_laiyuan}", systemInfo.getPcnm());
		systemInfo = systemDao.get(Long.valueOf(thesis.getThesisType()));
		m.put("#{yuanguan}", systemInfo.getSystemCategory().getPknm());
		m.put("#{timu_type}", systemInfo.getPcnm());
		m.put("#{jianshu}", thesis.getThesisContent());
		m.put("#{mubian}", thesis.getThesisDesignGoal());
		m.put("#{computer}", thesis.getComputerTime() == null ? "" : thesis.getComputerTime().toString());
		m.put("#{tuzhi}", thesis.getPectureCnt() == null ? "" : thesis.getPectureCnt().toString());
		m.put("#{dianlu}", thesis.getCircuitboardCnt() == null ? "" : thesis.getCircuitboardCnt().toString() );
		m.put("#{wenxian}", thesis.getInformationCnt() == null ? "" : thesis.getInformationCnt().toString());
		m.put("#{biji}", thesis.getReadwriterCnt() == null ? "" : thesis.getReadwriterCnt().toString());
		m.put("#{cankao}", thesis.getOpenThesisReference() == null ? "" : thesis.getOpenThesisReference());
		m.put("#{ji_yijian}", thesis.getThesisFile().getSetTheGroupReview() == null ? "" : thesis.getThesisFile().getSetTheGroupReview());
		m.put("#{ji_name}",thesis.getThesisFile().getSetTheGroupDesign() == null ? "" : thesis.getThesisFile().getSetTheGroupDesign());
		
		Date dates = thesis.getThesisFile().getSetTheGroupDesignTime();
		
		m.put("#{ji_yyyy}", DateUtils.toString(dates, "yyyy"));
		m.put("#{ji_mm}", DateUtils.toString(dates, "MM"));
		m.put("#{ji_dd}", DateUtils.toString(dates, "dd"));
		
		m.put("#{yuan_yijian}", thesis.getThesisFile().getSetTheBaseReview());
		m.put("#{yuan_name}", thesis.getThesisFile().getSetTheBaseDesign());
		
		dates = thesis.getThesisFile().getSetTheBaseDesignTime();
		m.put("#{yuan_yyyy}", DateUtils.toString(dates, "yyyy"));
		m.put("#{yuan_mm}", DateUtils.toString(dates, "MM"));
		m.put("#{yuan_dd}", DateUtils.toString(dates, "dd"));
		m.put("#{student_name}", thesis.getStudentName());
		m.put("#{class}", studentDao.findUniqueBy("studentNo", thesis.getStudentNo()).getClasses());
		m.put("#{student_no}", thesis.getStudentNo());
		return m;
	}
	
	private Map<String,String> task(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		m.put("#{titile}", thesis.getTitile());
		m.put("#{teacher}", thesis.getTeacherName());
		m.put("#{teacher_post}", thesis.getTeacherPost());
		m.put("#{mudi}", thesis.getThesisFile().getOpenTaskTarget() == null ? "" : thesis.getThesisFile().getOpenTaskTarget());
		m.put("#{neirong}", thesis.getThesisFile().getOpenTaskContent() == null ? "" : thesis.getThesisFile().getOpenTaskContent());
		m.put("#{jindu}", thesis.getThesisFile().getOpenTaskSchedule() == null ? "" : thesis.getThesisFile().getOpenTaskSchedule());
		m.put("#{ziling}", thesis.getThesisFile().getOpenTaskReference() == null ? "" : thesis.getThesisFile().getOpenTaskReference());
		m.put("#{didian}", thesis.getThesisFile().getOpenTaskAnswerInfo() == null ? "" : thesis.getThesisFile().getOpenTaskAnswerInfo());
		m.put("#{ji_yijian}", thesis.getThesisFile().getOpenTaskGroupContent() == null ? "" : thesis.getThesisFile().getOpenTaskGroupContent());
		m.put("#{qianzhi}", thesis.getThesisFile().getOpenTaskGroupName() == null ? "" : thesis.getThesisFile().getOpenTaskGroupName());
		Date date = thesis.getThesisFile().getOpenTaskGroupDate();
		m.put("#{yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{mm}", DateUtils.toString(date, "MM"));
		m.put("#{_dd}", DateUtils.toString(date, "dd"));
		return m;
	}
	
	public String multTask(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_TASKDOC;
		String content = webPath + PATH_TASCKCONTENT;
		String desPath = webPath + TEMP_PATH + nowTime + "/";
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/任务书/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(task(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	private Map<String,String> qingkuang(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		Weeklydiary week = thesis.getWeeklydiaryMap().get(1L);
		m.put("#{teacher_content}", week.getTeacherContent() == null ? "" : week.getTeacherContent());
		m.put("#{teacher_name}", week.getDiaryTeacherName() == null ? "" : week.getDiaryTeacherName());
		Date date = week.getDiaryTeacherDate();
		m.put("#{teacher_yyyy}",DateUtils.toString(date, "yyyy"));
		m.put("#{teacher_mm}", DateUtils.toString(date, "MM"));
		m.put("#{teacher_dd}", DateUtils.toString(date, "dd"));
		m.put("#{content}", week.getDiaryContent());
		return m;
	}
	/**
	 * 总结 的数据处理
	 * @param thesis
	 * @return
	 */
	private Map<String,String> weekEnd(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		Weeklydiary week = thesis.getWeeklydiaryMap().get(20L);
		m.put("#{teacher_content}", week.getTeacherContent() == null ? "" : week.getTeacherContent());
		m.put("#{teacher_name}", week.getDiaryTeacherName() == null ? "" : week.getDiaryTeacherName());
		Date date = week.getDiaryTeacherDate();
		m.put("#{teacher_yyyy}",DateUtils.toString(date, "yyyy"));
		m.put("#{teacher_mm}", DateUtils.toString(date, "MM"));
		m.put("#{teacher_dd}", DateUtils.toString(date, "dd"));
		m.put("#{content}", week.getDiaryContent());
		return m;
	}
	
	private Map<String,String> week(Thesis thesis,Long weekNo){
		Map<String,String> m = new HashMap<String,String>();
		Weeklydiary week = thesis.getWeeklydiaryMap().get(weekNo);
		m.put("#{weekNo}", weekNo + "~" + weekNo + 1);
		m.put("#{teacher_content}", week.getTeacherContent() == null ? "" : week.getTeacherContent());
		m.put("#{teacher_name}", week.getDiaryTeacherName() == null ? "" : week.getDiaryTeacherName());
		Date date = week.getDiaryTeacherDate();
		m.put("#{teacher_yyyy}",DateUtils.toString(date, "yyyy"));
		m.put("#{teacher_mm}", DateUtils.toString(date, "MM"));
		m.put("#{teacher_dd}", DateUtils.toString(date, "dd"));
		m.put("#{content}", week.getDiaryContent());
		return m;
	}
	
	public String multQingkuang(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_QINGKUANG_DOC;
		String content = webPath + PATH_QINGKUANG_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/开题报告准备情况/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(qingkuang(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	public String multWEEK(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime,Long weekNo){
		String doc = webPath + PATH_WEEK;
		String content = webPath + PATH_WEEK_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/周记/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			for(Thesis t : e.getValue()){
				list = new ArrayList<Map<String,String>>();
				dpath = path + "/" + "第" + weekNo + "-" + (weekNo + 1) +"周记.doc";
				m = new HashMap<String,String>();
				m.putAll(week(t,weekNo));
				
				list.add(m);
				wordUtils.searchAndReplace(dpath, list);
			}
		}
		
		return desPath;
	}
	
	
	
	/**
	 * 总结
	 * @param theisOrderClass
	 * @param webPath
	 * @param nowTime
	 * @param weekNo
	 * @return
	 */
	public String multWEEKEnd(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_WEEK_END;
		String content = webPath + PATH_WEEK_END_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/周记/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/总结.doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(weekEnd(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	private Map<String,String> openReport(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		ThesisFile file = thesis.getThesisFile();
		m.put("#{student_name}",thesis.getStudentName());
		m.put("#{student_no}", thesis.getStudentNo());
		m.put("#{student_date}", DateUtils.toString(file.getOpenReportStudentDate(),"yyyy-MM-dd"));
		m.put("#{titile}", thesis.getTitile());
		m.put("#{teacher}", thesis.getTeacherName());
		m.put("#{beijing}", file.getOpenReportManual() == null ? "" : file.getOpenReportManual());
		m.put("#{neirong}", file.getOpenReportContent() == null ? "" : file.getOpenReportContent());
		m.put("#{jindu}", file.getOpenReportScheldule() == null ? "" : file.getOpenReportScheldule());
		m.put("#{cankao}", file.getOpenReportReference() == null ? "" : file.getOpenReportReference());
		m.put("#{zhidao_yijian}", file.getOpenReportTeacherTxt() == null ? "" : file.getOpenReportTeacherTxt());
		m.put("#{zhidao_name}", file.getOpenReportTeacherName() == null ? "" : file.getOpenReportTeacherName());
		Date date = file.getOpenReportTeacherDate();
		m.put("#{zhidao_yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{zhidao_mm}", DateUtils.toString(date,"MM"));
		m.put("#{zhidao_dd}", DateUtils.toString(date,"dd"));
		m.put("#{group_yijian}", file.getOpenReportGroupTxt());
		m.put("#{group_name}", file.getOpenReportGroupName());
		date = file.getOpenReportGroupDate(); 
		m.put("#{group_yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{group_mm}", DateUtils.toString(date, "MM"));
		m.put("#{group_dd}", DateUtils.toString(date, "dd"));
		return m;
	}
	
	public String multOpenReport(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_REPORT_DOC;
		String content = webPath + PATH_REPORT_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/开题报告/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(openReport(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	/**
	 * 理科答辩 - 指导教师
	 * @param theisOrderClass
	 * @param webPath
	 * @param nowTime
	 * @return
	 */
	public String multLiKeZhiDao(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_LI_KE_ZHIDAO;
		String content = webPath + PATH_LI_KE_ZHIDAO_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/评分-指导教师/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(liKeZhiDaoz(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	private Map<String,String> liKeZhiDaoz(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		ThesisFile file = thesis.getThesisFile();
		String sss = "";
		if(thesis.getThesisType() == 1){
			sss = "理工";
		}else{
			sss = "文管";
		}
		m.put("#{kelei}", sss);
		m.put("#{stuentName}",thesis.getStudentName());
		m.put("#{studentNo}", thesis.getStudentNo());
		List<ThesisScore> list = thesis.getThesisScore();
		List<ThesisScore> ll = Lists.newArrayList();
		for(ThesisScore s : list){
			Long f = new Long(2L);
			if(f.equals(s.getType())){
				ll.add(s);
			}
		}
		m.put("#{fen1}", ll == null || ll.isEmpty() || ll.get(0) == null ? " " : ll.get(0).getScore().toString());
		m.put("#{fen2}", ll == null || ll.isEmpty() || ll.get(1) == null ? " " : ll.get(0).getScore().toString());
		m.put("#{fen3}", ll == null || ll.isEmpty() || ll.get(2) == null ? " " : ll.get(0).getScore().toString());
		m.put("#{fen4}", ll == null || ll.isEmpty() || ll.get(3) == null ? " " : ll.get(0).getScore().toString());
		m.put("#{fen5}", ll == null || ll.isEmpty() || ll.get(4) == null ? " " : ll.get(0).getScore().toString());
		m.put("#{fen6}", thesis.getZhidaoScore() == null ? " " : thesis.getZhidaoScore().toString());
		
		m.put("#{teacherContext}", file.getDabianZhidaoContent());
		//对号符号
		String ss = "";
		String s1 = "";
		String no = "<span lang=EN-US style='font-size:12.0pt;font-family:Wingdings;mso-ascii-font-family:宋体;mso-hansi-font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt;mso-char-type:symbol;mso-symbol-font-family:Wingdings'><span style='mso-char-type:symbol;mso-symbol-font-family:Wingdings'>þ</span></span>";
		if(file.getDabianZhidaoIsOk() == null || 1L != file.getDabianZhidaoIsOk()){
			ss = "□";
			s1 = no;
		}else{
			ss = no;
			s1 = "□";
		}
		m.put("#{tongyi_duicuo}", ss);
		m.put("#{butongyi_duicuo}", s1);
		
		m.put("#{teacherName}", file.getDabianZhidaoName());
		
		Date date = file.getDabianZhidaoDate();
		m.put("#{yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{mm}", DateUtils.toString(date,"MM"));
		m.put("#{dd}", DateUtils.toString(date,"dd"));
		return m;
	}
	
	/**
	 * 理科答辩 - 评阅
	 * @param theisOrderClass
	 * @param webPath
	 * @param nowTime
	 * @return
	 */
	public String multPingyue(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_LI_KE_PINGYUE;
		String content = webPath + PATH_LI_KE_PINGYUE_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/评分-评阅教师/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(pingyue(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	private Map<String,String> pingyue(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		ThesisFile file = thesis.getThesisFile();
		String sss = "";
		if(thesis.getThesisType() == 1){
			sss = "理工";
		}else{
			sss = "文管";
		}
		m.put("#{kelei}", sss);
		m.put("#{studentName}",thesis.getStudentName());
		m.put("#{studentNo}", thesis.getStudentNo());
		List<ThesisScore> list = thesis.getThesisScore();
		List<ThesisScore> ll = Lists.newArrayList();
		for(ThesisScore s : list){
			Long f = new Long(3L);
			if(f.equals(s.getType())){
				ll.add(s);
			}
		}
		m.put("#{fen1}", ll.get(0).getScore().toString());
		m.put("#{fen2}", ll.get(1).getScore().toString());
		m.put("#{fen3}", ll.get(2).getScore().toString());
		m.put("#{fen4}", ll.get(3).getScore().toString());
		m.put("#{fen5}", ll.get(4).getScore().toString());
		m.put("#{fen6}", thesis.getPingyueScore().toString());
		
		m.put("#{titile}", thesis.getTitile());
		m.put("#{pingyueTitle}", "");
		
		m.put("#{pingyueContext}", file.getDabianPingyueContent());
		//对号符号
		String ss = "";
		String s1 = "";
		String no = "<span lang=EN-US style='font-size:12.0pt;font-family:Wingdings;mso-ascii-font-family:宋体;mso-hansi-font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt;mso-char-type:symbol;mso-symbol-font-family:Wingdings'><span style='mso-char-type:symbol;mso-symbol-font-family:Wingdings'>þ</span></span>";
		if(1L != file.getDabianZhidaoIsOk()){
			ss = "□";
			s1 = no;
		}else{
			ss = no;
			s1 = "□";
		}
		m.put("#{tongyi_duicuo}", ss);
		m.put("#{butongyi_duicuo}", s1);
		
		m.put("#{pingyueName}", file.getDabianZhidaoName());
		
		Date date = file.getDabianZhidaoDate();
		m.put("#{yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{mm}", DateUtils.toString(date,"MM"));
		m.put("#{dd}", DateUtils.toString(date,"dd"));
		return m;
	}
	
	/**
	 * 理科答辩 - 答辩
	 * @param theisOrderClass
	 * @param webPath
	 * @param nowTime
	 * @return
	 */
	public String multDabian(Map<String,List<Thesis>> theisOrderClass,String webPath,String nowTime){
		String doc = webPath + PATH_LI_KE_DABIAN;
		String content = webPath + PATH_LI_KE_DABIAN_CONTENT;
		String desPath = webPath + TEMP_PATH + nowTime;
		File file = new File(desPath);
		if(!file.exists()){
			file.mkdir();
		}
		String path = desPath + "/评分-答辩委员会/";
		file = new File(path);
		if(!file.exists()){
			file.mkdir();
		}
		Map<String,String> m = null;
		List<Map<String,String>> list;
		WordUtils wordUtils = new WordUtils(doc,content);
		String dpath = null;
		for(Map.Entry<String, List<Thesis>> e : theisOrderClass.entrySet()){
			
			dpath = path + "/" + e.getKey() +".doc";
			list = new ArrayList<Map<String,String>>();
			for(Thesis t : e.getValue()){
				m = new HashMap<String,String>();
				m.putAll(dabian(t));
				
				list.add(m);
			}
			wordUtils.searchAndReplace(dpath, list);
		}
		
		return desPath;
	}
	
	private Map<String,String> dabian(Thesis thesis){
		Map<String,String> m = new HashMap<String,String>();
		ThesisFile file = thesis.getThesisFile();
		String sss = "";
		if(thesis.getThesisType() == 1){
			sss = "理工";
		}else{
			sss = "文管";
		}
		m.put("#{kelei}", sss);
		m.put("#{studnetName}",thesis.getStudentName());
		m.put("#{studentNo}", thesis.getStudentNo());
		List<ThesisScore> list = thesis.getThesisScore();
		List<ThesisScore> ll = Lists.newArrayList();
		for(ThesisScore s : list){
			Long f = new Long(4L);
			if(f.equals(s.getType())){
				ll.add(s);
			}
		}
		m.put("#{fen1}", ll.get(0).getScore().toString());
		m.put("#{fen2}", ll.get(1).getScore().toString());
		m.put("#{fen3}", ll.get(2).getScore().toString());
		m.put("#{fen4}", ll.get(3).getScore().toString());
		m.put("#{fen5}", ll.get(4).getScore().toString());
		m.put("#{fen6}", thesis.getDabianScore().toString());
		m.put("#{fen7}", thesis.getZhidaoScore().toString());
		m.put("#{fen8}", thesis.getPingyueScore().toString());
		m.put("#{fen9}", thesis.getDabianScore().toString());
		m.put("#{fen10}", thesis.getAllScore().toString());
		
		m.put("#{titile}", thesis.getTitile());
		
		m.put("#{dabianContent}", file.getDabianSceneContent());
		m.put("#{dabianName}", file.getDabianSceneName());
		
		Date date = file.getEndScoreDate();
		m.put("#{da_yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{da_mm}", DateUtils.toString(date,"MM"));
		m.put("#{da_dd}", DateUtils.toString(date,"dd"));
		
		String no = "<span lang=EN-US style='font-size:12.0pt;font-family:Wingdings;mso-ascii-font-family:宋体;mso-hansi-font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt;mso-char-type:symbol;mso-symbol-font-family:Wingdings'><span style='mso-char-type:symbol;mso-symbol-font-family:Wingdings'>þ</span></span>";
		
		String youxu = "□";
		String lianghao = "□";
		String zhong = "□";
		String jihe = "□";
		String bujige = "□";
		
		String score = thesis.getEndScore();
		if("优秀".equals(score)){
			youxu = no;
		}else if("良好".equals(score)){
			lianghao = no;
		}else if("中等".equals(score)){
			zhong = no;
		}else if("及格".equals(score)){
			jihe = no;
		}else if("不及格".equals(score)){
			bujige = no;
		}
		
		m.put("#{duicuo1}", youxu);
		m.put("#{duicuo2}", lianghao);
		m.put("#{duicuo3}", zhong);
		m.put("#{duicuo4}", jihe);
		m.put("#{duicuo5}", bujige);
		
		m.put("#{zong_name}", file.getEndScoreName());
		
		date = file.getEndScoreDate();
		m.put("#{z_yyyy}", DateUtils.toString(date, "yyyy"));
		m.put("#{z_mm}", DateUtils.toString(date,"MM"));
		m.put("#{z_dd}", DateUtils.toString(date,"dd"));
		return m;
	}
	
	/**
	 * 导出蓝皮书
	 * @param ids
	 * @param flag
	 * @param webPath
	 * @return
	 */
	public String expLanPi(List<Long> ids,String webPath){
		
		//把list<Id>整理到map中
		Thesis thesis = null;
		/** key -班级，value - 班级的所有题目 */
		Map<String,List<Thesis>> map = new HashMap<String,List<Thesis>>();
		List<Thesis> list = null;
		Student student = null;
		List<Thesis> ll = Lists.newArrayList();
		for(Long id : ids){
			thesis = thesisDao.get(id);
			ll.add(thesis);
			
			student = studentDao.findUniqueBy("studentNo", thesis.getStudentNo());
			list = map.get(student.getClasses());
			if(list == null || list.isEmpty()){
				list = new ArrayList<Thesis>();
				list.add(thesis);
				map.put(student.getClasses(), list);
			}else{
				list.add(thesis);
			}
		}
		//每次操作获取的所有文件都放在一个目录下.便与后期压缩
		String nowTime = new Date().getTime() + "";
		String desPath = webPath + TEMP_PATH + nowTime;
		
		
		for(Thesis t : ll){
			List<Thesis> l1 = Lists.newArrayList();
			
			student = studentDao.findUniqueBy("studentNo", t.getStudentNo());
			String ns =  nowTime + "/" + student.getStudentName() + "_" + student.getStudentNo();
			String f = webPath + TEMP_PATH +  ns;
			File file = new File(f);
			if(!file.exists()){
				file.mkdirs();
			}
			
			l1.add(t);
			map = new HashMap<String, List<Thesis>>();
			map.put(student.getClasses(), l1);
			//蓝皮书里没有论证书
			//	desPath = multLiti(map,webPath,nowTime);
			 multTask(map, webPath, ns);
			multQingkuang(map, webPath, ns);
			multOpenReport(map, webPath, ns);
			multWEEK(map, webPath, ns, 3L);
			multWEEK(map, webPath, ns, 5L);
			multWEEK(map, webPath, ns, 7L);
			multWEEK(map, webPath, ns, 9L);
			multWEEK(map, webPath, ns, 11L);
			multWEEK(map, webPath, ns, 13L);
			multWEEKEnd(map, webPath, ns);
			multLiKeZhiDao(map, webPath, ns);
			multPingyue(map, webPath, ns);
			multDabian(map, webPath, ns);
		}
		return desPath;
	}

}

